package my.ts.code.adapter;

import java.util.ArrayList;

import my.ts.code.objects.Item;
import my.ts.code.viewgroup.CategoryItem;
import my.ts.code.viewgroup.LoadingMoreItem;
import my.ts.code.viewgroup.MoreItem;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CategoryAdapter extends ArrayAdapter<Item> {

	ArrayList<Item> myArray;
	int res;
	Context context;

	public CategoryAdapter(Context context, int textViewResourceId,
			ArrayList<Item> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub

		this.context = context;
		res = textViewResourceId;
		myArray = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// // TODO Auto-generated method stub
		View itemview = convertView;
		final Item item = myArray.get(position);
		if (item != null) {
			if (item.getMore() == 0) {
				itemview = new CategoryItem(getContext());

				TextView tvName = ((CategoryItem) itemview).title;
				tvName.setText(item.getCategoryName());
			} else if (item.getMore() == 1) {
				itemview = new MoreItem(getContext());
			} else if (item.getMore() == 2) {
				itemview = new LoadingMoreItem(getContext());
			}

			// TextView tvName = ((CategoryItem) itemview).title;
			// tvName.setText(item.getCategoryName());
		}
		return itemview;
	}

}
